﻿using Autofac.Core;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SheepStorage.API.Application.Command.BuildingManagementCommand;
using SheepStorage.API.Application.Command.SheepWeightCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.DataImp;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Controllers
{
    /// <summary>
    /// 羊只称重管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SheepWeightController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ISheepWeightService service;

       


        public SheepWeightController(IMediator mediator, ISheepWeightService service)
        {
            _mediator = mediator;
            this.service = service;
        }

        /// <summary>
        /// 羊只称重添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> Create(SheepWeightCreateCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        ///羊只称重显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<Results<PageOutput<SheepWeight>>> GetSheepWeight(SheepWeightListCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 羊只称重删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DelSheepWeight(SheepWeightDelCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 羊只称重反填
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpGet]
    
        public async Task<Results<SheepWeight>> GetFtSheepWeight(int sheepWeightId)
        {
            return Results<SheepWeight>.DataResult(service.GetFtSheepWeight(sheepWeightId));
        }
      

        /// <summary>
        /// 羊只称重修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<Results<int>> Update(SheepWeightUpdaCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 批量删除羊只称重
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DelRangeSheepWeight(SheepWeightDelRangeCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
